1 00:00:00,510 --> 00:00:03,290 Hello and welcome to this lecture. 2 00:00:03,600 --> 00:00:12,330 In this lecture we aren't going to be creating some logic for move in the puddle the moment the pad 3 00:00:12,330 --> 00:00:17,890 all his static so does not respond to movement. 4 00:00:18,690 --> 00:00:22,230 This is what the paddle looks like at the moment. 5 00:00:22,230 --> 00:00:24,960 So the little rectangle in blue there. 6 00:00:24,990 --> 00:00:33,230 So if you press your left and right mouse key you will notice there is no movement at all. 7 00:00:33,360 --> 00:00:39,600 That's because we have not implemented the logic that will control that movement. 8 00:00:39,600 --> 00:00:43,090 So this is what we'll do in this lecture. 9 00:00:43,910 --> 00:00:48,690 All right I have caught my javascript file here. 10 00:00:48,930 --> 00:00:54,760 So we go right down to where we defined the draw function. 11 00:00:54,810 --> 00:01:00,830 So this is where we are going to implement the logic for moving the paddle. 12 00:01:00,900 --> 00:01:05,790 So this is the core function so this is where we go to implement it. 13 00:01:05,790 --> 00:01:08,820 So we've got some more that code in here. 14 00:01:08,820 --> 00:01:11,720 So we are just going to implement it. 15 00:01:11,730 --> 00:01:22,040 Just underneath here with inside the drill function to save time I have written the piece of code already. 16 00:01:22,230 --> 00:01:26,320 So this is the first part of the code. 17 00:01:26,330 --> 00:01:28,720 This statement here. 18 00:01:29,610 --> 00:01:33,250 So this is the first part of the code. 19 00:01:33,500 --> 00:01:44,070 This same that if the right is press them is the right cursor or the right key on the keyboard is pressed 20 00:01:44,910 --> 00:01:52,960 the variable pad X will move the paddle 7 pixels. 21 00:01:53,090 --> 00:02:00,140 Kate remember we defined all these variables later on the cause saw powder X.. 22 00:02:00,240 --> 00:02:09,400 This is what part of exis is the whiff is encumbers with minus the paddle with divided by two. 23 00:02:09,630 --> 00:02:19,440 Right so that's what that is so saying here that if the right key or cursings Press moved the pad all 24 00:02:19,650 --> 00:02:21,450 seven pixels. 25 00:02:21,480 --> 00:02:30,910 That's why there is a loss however or else what if the left is pressed more. 26 00:02:31,020 --> 00:02:35,740 The paddle minus seven in the opposite direction. 27 00:02:35,880 --> 00:02:37,300 So that's what that means. 28 00:02:37,390 --> 00:02:47,700 Okay so if the right is pressed move the paddle 7 pixels and if it's left move it 7 pixels the other 29 00:02:47,700 --> 00:02:48,720 direction. 30 00:02:48,750 --> 00:02:51,230 So let's say this and run this. 31 00:02:51,290 --> 00:02:56,900 I run the code so you can see while you are right so this is the paddle at the moment. 32 00:02:56,910 --> 00:02:59,760 So at the moment if I press the left. 33 00:03:00,690 --> 00:03:09,900 If you notice is pedalos disappear off the screen and if I press the right it disappears off the screen 34 00:03:09,960 --> 00:03:10,820 as well. 35 00:03:11,040 --> 00:03:16,440 Okay so let's try and control the paddle. 36 00:03:17,530 --> 00:03:20,510 Okay this is gone out of the. 37 00:03:20,810 --> 00:03:28,890 So we have to try and correct that so that it stays within the compass all right. 38 00:03:28,900 --> 00:03:39,950 I have implemented some extra things into the code to prevent the pad from leaving the canvas saw So 39 00:03:40,140 --> 00:03:41,220 this is what it is say. 40 00:03:41,240 --> 00:03:52,050 If the right cursor is pressed and this loop symbol's game is and and the pad all variable the variable 41 00:03:52,130 --> 00:03:59,130 padlocked X is the less than the can that's a minus. 42 00:03:59,240 --> 00:04:07,150 Me with the paddle and then move the pixels move the pad all 7 pixels. 43 00:04:07,440 --> 00:04:12,110 Okay so if I were pressing the right cursor and this condition is true. 44 00:04:12,240 --> 00:04:16,890 Move it to 7 pixels from the right. 45 00:04:16,890 --> 00:04:22,880 In that case it will not leave the compass because of this extra implementation here. 46 00:04:22,920 --> 00:04:24,210 Which I've said. 47 00:04:24,210 --> 00:04:33,360 If there were when you press the right cursor and the pad or the variable paddleboat X is less than 48 00:04:33,360 --> 00:04:38,780 the width of the canvas minus B with the paddle. 49 00:04:39,210 --> 00:04:42,970 If the condition is true then move with 7 pixels. 50 00:04:43,200 --> 00:04:45,260 Else it is not. 51 00:04:45,270 --> 00:04:56,630 If you press the left cursor instead and the pad all x variable is greater than the zero from the left 52 00:04:56,640 --> 00:04:58,940 as long as is greater than zero. 53 00:04:59,040 --> 00:05:04,880 Then you can move the pad all 7 pixels away which is mine of 7. 54 00:05:04,890 --> 00:05:06,530 The other in the other Derek. 55 00:05:07,650 --> 00:05:18,180 So what this court is saying is if the curse of the left curser here is pressed the paddle will move 56 00:05:18,420 --> 00:05:21,670 several pixels to the left. 57 00:05:21,930 --> 00:05:32,290 If we press the right key right cursor it will move several pixels from the right. 58 00:05:32,460 --> 00:05:35,940 The paddle may have seven pixels to the right. 59 00:05:35,940 --> 00:05:42,130 And if you press the left to a more seven pixels to the left or right. 60 00:05:42,300 --> 00:05:45,020 That's what Big code will do. 61 00:05:45,270 --> 00:05:46,000 Okay. 62 00:05:46,320 --> 00:05:55,200 We've also implemented extra things here to prevent the pad all from leave in the camp that's previously 63 00:05:55,200 --> 00:05:58,660 without this extra things we've implemented here. 64 00:05:58,660 --> 00:06:01,570 The paddle was leave in the comebacks. 65 00:06:01,770 --> 00:06:02,440 Okay. 66 00:06:02,640 --> 00:06:09,150 So what we're seeing now is that the the paddle x position is part of lexia is variable. 67 00:06:09,150 --> 00:06:19,680 We use it to move from 0 on the left to from the left side of the come from zero minus the with of the 68 00:06:19,680 --> 00:06:20,460 paddle. 69 00:06:20,730 --> 00:06:21,150 Okay. 70 00:06:21,150 --> 00:06:22,360 To the right size. 71 00:06:22,410 --> 00:06:28,980 Right so with that in place the count the paddles should not leave the compass. 72 00:06:29,470 --> 00:06:30,030 Okay. 73 00:06:30,060 --> 00:06:38,570 Now that we've done that to save save your work and we know we've got all the functions in place now 74 00:06:38,580 --> 00:06:46,950 so now if we try and go back to that you see that the paddle can be moved and it will not leave the 75 00:06:46,950 --> 00:06:54,090 screen you can see that it does not leave the comebacks no matter how far you press it to the left or 76 00:06:54,090 --> 00:06:56,260 how far you press it to the right. 77 00:06:56,280 --> 00:07:01,620 It does not leave the compass because of the front perimenopause. 78 00:07:01,740 --> 00:07:05,150 We have put in place to control that. 79 00:07:05,490 --> 00:07:12,650 All right so sit for this shot on the logic to move the panel. 80 00:07:12,690 --> 00:07:16,920 So we've got our game you know looking good. 81 00:07:16,950 --> 00:07:26,610 We now have to implement a game all of us so there's no point playing a game that one can not lose at 82 00:07:26,610 --> 00:07:30,020 some point in me you should lose the game. 83 00:07:30,060 --> 00:07:31,360 The purpose of the game. 84 00:07:31,440 --> 00:07:39,060 So we are going to create the mechanics for the game loss way is possible for someone to lose the game 85 00:07:39,750 --> 00:07:40,790 in the next lecture.